package com.qyhl.webtv.module_news.news.union.town.meetingroom;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.entity.news.MeetingRoomListBean;
import com.qyhl.webtv.module_news.common.NewsUrl;

import java.util.List;

/**
 * Created by qyhl on 2018/3/1.
 */

public class MeetingRoomModel implements MeetingRoomContract.MeetingRoomModel {

    private MeetingRoomPresenter mPresenter;

    public MeetingRoomModel(MeetingRoomPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    /**
     * 获取留言列表
     *
     * @param streetId
     * @param meetingId
     */
    @Override
    public void getMeetingList(String streetId, final String meetingId) {

        EasyHttp.get(NewsUrl.GET_MEETING_ROOM_LIST)
                .params("streetId", streetId)
                .params("meetingId", meetingId)
                .execute(new SimpleCallBack<List<MeetingRoomListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if ("0".equals(meetingId)) {
                            mPresenter.getListError(0, "网络异常，加载失败！");
                        } else {
                            if (e.getCode() == 202) {
                                mPresenter.getListError(3, "no more");
                            } else {
                                mPresenter.getListError(4, "解析异常，加载失败！");
                            }
                        }
                    }

                    @Override
                    public void onSuccess(List<MeetingRoomListBean> meetingRoomListBeans) {
                        if ("0".equals(meetingId)) {
                            mPresenter.getListSuccess(meetingRoomListBeans, false);
                        } else {
                            mPresenter.getListSuccess(meetingRoomListBeans, true);
                        }
                    }
                });

    }
}
